package ca;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;

public class CertificateUtil {
    public static KeyStore getKeyStore(String keyStorePath, String keystore_password) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        FileInputStream is = new FileInputStream(keystore_password);
        ks.load(is, keystore_password.toCharArray());
        is.close();
        return ks;
    }

    private static PrivateKey getPrivateKeyByKeyStore(String keyStorePath,String alias, String keystore_password,String ca_password) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException {
        KeyStore keyStor = getKeyStore(keyStorePath, keystore_password);
        return (PrivateKey) keyStor.getKey(alias, ca_password.toCharArray());
    }

    public static Certificate getCertificate(String certificatePath) {
//        CertificateFactory.getInstance();
        return null;
    }
}
